#ifndef MODBUS_CTR_H
#define MODBUS_CTR_H

#include <QObject>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QModbusRtuSerialMaster>
#include <QModbusClient>
#include <QTimer>
#include "loadconfig.h"

typedef enum
{
    Connected,
    DisConnect,
    ErrConnect,
    ErrRead,
    _MB_OK
}ModbusState_t;

class Modbus_ctr : public QObject
{
    Q_OBJECT
public:
    explicit Modbus_ctr(QObject *parent = nullptr);
    QStringList refreshSerial();
    bool serialFlag = true; //串口刷新标志位
    QVector<uint16_t> ModbusData;

private:
    QModbusClient  *modbusDevice = nullptr;
    int id = 0;
    QStringList Portinfo,oldPortList,newPortList;
    int newListCount,oldLisrCount;
signals:
    void serialUpdate(QStringList);
    void ModbusState(ModbusState_t);
    void ModbusDataConver(QVector<uint16_t>);
public slots:
    void on_sysTick();
    void on_SerialConf(LoadConfig *config, QString com);
    void on_readModbus(int , int, bool end);
    void on_WriteModbus(uint16_t addr, uint16_t val);
};

#endif // MODBUS_CTR_H
